Convert number to enum
This crate provides a derive macro to generate a function for converting a primitive integer into the corresponding variant of an enum.
The generated function is named n
and has the following signature:
where Repr
is an integer type of the right size as described in more detail
below.
Example
use N;
Signature
The generated signature depends on whether the enum has a #[repr(..)]
attribute. If a repr
is specified, the input to n
will be required to be of
that type.
// expands to:
On the other hand if no repr
is specified then we get a signature that is
generic over a variety of possible types.
Discriminants
The conversion respects explicitly specified enum discriminants. Consider this enum:
Here Letter::n(65)
would return Some(Letter::A)
.